<?php require_once("Log.class.php");

/**
 *  
 */

class LogRead extends Log 
{
    private $_filename;
    private $_file;
    /**
     * @access public
     */
    public function __construct($fileName)
    {
        date_default_timezone_set('Europe/Paris'); 
        $this->_fileName = $fileName;
        if(!file_exists($fileName)) 
        {
            throw new Exception('LogRead:: ' . $fileName . ' could not be found');
        }
        else 
        {
            if(!($this->_file = file($fileName)))
            {
                Throw new Exception('Logfile ' . $fileName . ' could not be read');
            }
            else 
            {
                foreach($this->_file as $line => $log) 
                {
                    $this->_file[$line] = explode(',', $log);
                    foreach($this->_file[$line] as $lognr => $logname)
                    {
                        $this->_file[$line][$lognr] = trim($logname);
                    }
                }
            }
        }
    }
    
    public function __toString()
    {
        $html = sprintf("
                <h1>Log Management</h1>
                <table border=1 style=\"border: 1px solid lightgrey\">
                    <tr style=\"border: 1px solid lightgrey\>
                       <th>Date:</th><th>Time:</th><th>Group:</th><th>Error message:</th><th>IP-adress:</th><th>Filename:</th>
                    </tr>
                    ");
        
        foreach($this->_file as $record)
        {
            $html .= sprintf("
            <tr>
                <td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>
            </tr>
            ", date('Y-m-d',$record[0]), 
               date('H:i', $record[0]), 
               $record[1], 
               $record[4], 
               $record[2],
               $record[3]);
        }
        $html .= "</table>";
        return $html;
    }
    
    
    /**
     * @access public
     */
    public function __destruct()
    {
        
    }
}

$logread = new LogRead('Log.class.log');
echo $logread;